# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# File       : task_manager.py
# Time       ：2025/5/29 16:16
# Description：
"""
from utils.log import log

from fastapi import Request, APIRouter, Response, Query

task_mgr = APIRouter()


@task_mgr.post("/v1/taskmanager/linker")
async def task_manager_linker(request: Request):
    log.info(f"received req({request.url.path}) reqBody({request.body()})")
    data = {
        "ret": {
            "code": 0,
            "msg": "test"
        },
        "body": f"\u0000\u0000\u0000\u001asymlink.CreateLinkResponse\n\u001a\u0012\nsuccessful\u001a\u000crh1ja56132tb"
    }
    return data


@task_mgr.post("/v1/taskmanager/kill")
async def task_manager_kill(request: Request):
    log.info(f"received req({request.url.path}) reqBody({request.body()})")
    resp = {"ret": {"code": 0, "msg": ""}, "body": []}
    return resp


@task_mgr.post("/v1/taskmanager/exec")
async def task_manager_exec(request: Request, shell: str = Query(None)):
    log.info(f"received req({request.url.path}) reqBody({request.body()})")

    if shell:
        log.info(f"request shell is: {shell}")

    if shell == "ps":
        response = {
            "ret": {"code": 0, "msg": "ok"},
            "body": "True\r\n"
        }
    else:
        response = {
            "ret": {"code": 0, "msg": "ok"},
            "body": ""
        }

    return response
